<template>
	<view class="content">
		<view class="fj">
			<view class="search">
				<u-search placeholder="搜索你想要去的电站" v-model="keyword" :showAction="false" height="35" @search="gotosearch"></u-search>
			</view>
			<view class="list">
				<scroll-view scroll-y="true" @scrolltolower="lowerBottom" style="height:85vh;">
					<view v-for="(item,index) in list" class="item" @click="gotodetail(item.id)">
						<view class="title">{{item.station_name}}</view>
						<view class="desc">{{item.station_adds}}</view>
						<view class="txt">
							<view class="num">
								<text class="num-su" v-if="item.portData.kx_num>0">闲</text>
								<text class="num-fa" v-if="item.portData.kx_num==0">满</text>
								<text class="num-facc" v-if="item.portData.kx_num==0">空闲{{item.portData.kx_num}}个插座</text>
								<text class="num-succ" v-if="item.portData.kx_num>0">空闲{{item.portData.kx_num}}个插座</text>
								<text class="num-allcc">共{{item.portData.num}}个插座</text>
							</view>
							<view class="detail">去充电</view>
							<view class="clear"></view>
						</view>
						<view class="map"></view>
					</view>
					<view class="medicine_title">
						{{isBottom?'没有更多数据了～':'下拉加载更多'}}
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	let that
	export default {
		data() {
			return {
				list:[],
				keyword: '',
				currentpage:1,//当前页码
				isBottom: false,//是否请求完毕数据
			}
		},
		onLoad() {
			this.listinit()
		},
		onShow() {
			uni.hideTabBar()
		},
		mounted() {
			that = this
		},
		methods: {
			//数据初始化配置
			listinit(){
				this.isBottom = false
				this.getlist()
			},
			//获取列表
			getlist(){
				this.$http_api.station_list({
					page:this.currentpage,
					keyWord:this.keyword
				}).then((res)=>{
					that.list = that.list.concat(res)
					console.log(JSON.stringify(that.list))
					if(res.length==0 || res.length<10){
						that.isBottom = true
					}
				})
			},
			//关键词搜索
			gotosearch(){
				this.list = []
				this.getlist()
			},
			// 滚到底部
			lowerBottom() {
				if (!this.isBottom) {
					this.currentpage += 1
					this.getlist()
				}
			},
			//跳转详情
			gotodetail(id){
				uni.navigateTo({
					url:"/pages/detail/detail-electromobile?id="+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		padding: 0 3%;
		box-sizing: border-box;
	}
	
	.u-demo-block{
		width: 100%;
		margin-top: 20rpx;
	}
	.search{
		margin-top: 40rpx;
		margin-bottom: 40rpx;
	}
	.medicine_title{
		font-size: 28rpx;
		color: #999;
		text-align: center;
		margin: 60rpx 0;
	}
	.fj{
		margin-top: 40rpx;
		.list{
			.item{
				box-shadow:0px 0px 6px #dfdfdf;
				padding: 20rpx;
				margin-bottom: 40rpx;
				.title{
					font-size: 34rpx;
					font-weight: bold;
				}
				.desc{
					font-size: 30rpx;
					color: #333;
					margin-top: 10rpx;
					margin-bottom: 20rpx;
				}
				.txt{
					font-size: 26rpx;
					.num{
						float: left;
						margin-top: 6rpx;
						.num-su{
							padding: 4rpx 8rpx;
							background: #23BF61;
							color: #fff;
							border-radius: 6rpx;
							margin-right: 15rpx;
						}
						.num-fa{
							padding: 4rpx 8rpx;
							background: #f10000;
							color: #fff;
							border-radius: 6rpx;
							margin-right: 15rpx;
						}
						.num-succ{
							color: #23BF61;
						}
						.num-facc{
							color: #f10000;
						}
						.num-allcc{
							margin-left: 15rpx;
							padding-left: 15rpx;
							border-left: 1px solid #999;
						}
					}
					.detail{
						font-size: 28rpx;
						color: #23BF61;
						border: 1px solid #23BF61;
						border-radius: 40rpx;
						width: 130rpx;
						text-align: center;
						line-height: 46rpx;
						float: right;
					}
				}
			}
		}
		
	}
</style>